/* @formatter:off
 * Copyright (c) 2011 Lucas <lucas03093@gmail.com>
 * 
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
/* @formatter:on */

package nu.korkad.daytracker.info;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Notify
{
    /**
     * @param msg
     *            String, shown quickly when the notfication is created
     * @param title
     *            String, shown in the expanded notification bar
     * @param desc
     *            String, shown in the expanded notification bar
     * @param url
     *            String, url to open when clicking the notification
     * @param context
     */
    public void updateNotification(String msg, String title, String desc, String url, Context context)
    {
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(android.R.drawable.stat_notify_error, msg, System.currentTimeMillis());
        
        // The PendingIntent will launch activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Uri.parse(url)), 0);
        
        // Set title and description for expanded notification
        notification.setLatestEventInfo(context, title, desc, contentIntent);
        
        // Settings for the notification
        notification.flags |= Notification.FLAG_AUTO_CANCEL; // cancel when selected
        
        manager.notify(2, notification);
    }
}
